package com.project.service.impl;

import com.project.bean.StudentBean;
import com.project.mapper.IStudentMapper;
import com.project.service.IStudentService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentService extends BaseService implements IStudentService {
    @Override
    public void changeRoom(int id, int roomId) {
        SqlSession session =this.getSession();
        IStudentMapper mapper=session.getMapper(IStudentMapper.class);
        mapper.changeRoom(id,roomId);
        session.commit();
        session.close();

    }

    @Override
    public List<StudentBean> findByltems(String name, String className, String address) {
        SqlSession session =this.getSession();
        IStudentMapper mapper=session.getMapper(IStudentMapper.class);
        List<StudentBean>list=mapper.findByltems(name,className,address);

        session.close();
        return list;
    }

    @Override
    public void addStudent(StudentBean studentBean) {
        SqlSession session =this.getSession();
        IStudentMapper mapper=session.getMapper(IStudentMapper.class);
        mapper.addStudent(studentBean);
        session.commit();
        session.close();

    }

    @Override
    public void deleteStudent(int id) {
        SqlSession session =this.getSession();
        IStudentMapper mapper=session.getMapper(IStudentMapper.class);
        mapper.deleteStudent(id);
        session.commit();
        session.close();


    }

    @Override
    public StudentBean findById(int id) {
        SqlSession session =this.getSession();
        IStudentMapper mapper=session.getMapper(IStudentMapper.class);
        StudentBean studentBean=mapper.findById(id);
        session.close();
        return studentBean;
    }
}
